package oocl.custormer.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oocl.custormer.dao.MerchantDao;
import oocl.custormer.po.Merchant;
import oocl.custormer.util.DbUtil;


public class MerchantDaoImpl implements MerchantDao{
	public List<Merchant> findAllMerchant() {
	List<Merchant> mm = new ArrayList<Merchant>();
	String sql = "select * from Merchant";
	Connection con = null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	con = DbUtil.connect();
	try {
		pst = con.prepareStatement(sql);
		rs = pst.executeQuery();
		System.out.println(rs);
		while (rs.next()) {
			int mId = rs.getInt("mId");
			String mTel = rs.getString("mTel");
			System.out.println(mTel);
			String mPersonName = rs.getString("mPersonName");
			System.out.println(mPersonName);
			String mBrand = rs.getString("mBrand");
			String mLocation= rs.getString("mLocation");
			String mLogoPath= rs.getString("mLogoPath");
			Merchant md = new Merchant(mId,mPersonName,mTel,mLocation,mBrand,mLogoPath);
			mm.add(md);
		}
	} catch (SQLException e) {

		e.printStackTrace();
	} finally {
		DbUtil.free(con, pst, null);
	}
	return mm;
}

}


